package wysiwyg.layers
{
	import flash.display.DisplayObject;
	import flash.events.Event;
	
	import mx.collections.ArrayCollection;
	import mx.core.UIComponent;
	
	import wysiwyg.interfaces.Selectable;
	import wysiwyg.shapes.ShapeBase;
	public class Layer extends UIComponent implements Selectable
	{
		private static var layerCount:Number=1;
		public var label:String=(layerCount++).toString();
		public var selected:Boolean;
		public function Layer()
		{
			super();
		}
		public function select():void
		{
			selected=true;
			for each(var shape:ShapeBase in getChildrenShapes())
			{
				shape.select();
			}
			dispatchEvent(new Event("selected",true));
		}
		public function deselect():void
		{
			for each(var shape:ShapeBase in getChildrenShapes())
			{
				shape.deselect();
			}
			dispatchEvent(new Event("deselected",true));
			selected=false;
		}
		public function deselectShapes():void
		{
			for each(var shape:ShapeBase in getChildrenShapes())
			{
				shape.deselect();
			}
		}
		override public function addChild(child:DisplayObject):DisplayObject
		{
			if(child is ShapeBase)
				(child as ShapeBase).parentLayer=this;
			return super.addChild(child);
		}
		public function getChildrenShapes():ArrayCollection
		{
			var tempCollection:ArrayCollection=new ArrayCollection();
			for(var i:int=0;i<numChildren;i++)
			{
				if(getChildAt(i) is ShapeBase)
					tempCollection.addItem(getChildAt(i));
			}
			return tempCollection;
		}
	}
}